package com.jeesite.modules.pt.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.pt.entity.PtShichangBuzhou;
import com.jeesite.modules.pt.service.PtShichangBuzhouService;

/**
 * pt_shichang_buzhouController
 * @author 李寒冰
 * @version 2025-04-07
 */
@Controller
@RequestMapping(value = "${adminPath}/pt/ptShichangBuzhou")
public class PtShichangBuzhouController extends BaseController {

	@Autowired
	private PtShichangBuzhouService ptShichangBuzhouService;

	@Value("${pic.baseUrl}")
	private String houtaiPicBaseUrl;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public PtShichangBuzhou get(String id, boolean isNewRecord) {
		return ptShichangBuzhouService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("pt:ptShichang:view")
	@RequestMapping(value = {"list", ""})
	public String list(PtShichangBuzhou ptShichangBuzhou, Model model) {
		model.addAttribute("ptShichangBuzhou", ptShichangBuzhou);
		return "modules/pt/ptShichangBuzhouList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("pt:ptShichang:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<PtShichangBuzhou> listData(PtShichangBuzhou ptShichangBuzhou, HttpServletRequest request, HttpServletResponse response) {
		ptShichangBuzhou.setPage(new Page<>(request, response));
		Page<PtShichangBuzhou> page = ptShichangBuzhouService.findPage(ptShichangBuzhou);
		List<PtShichangBuzhou> list = page.getList();
		for (PtShichangBuzhou p : list) {
			String pic = p.getPic();
			p.setPic(houtaiPicBaseUrl+pic);
		}
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("pt:ptShichang:view")
	@RequestMapping(value = "form")
	public String form(PtShichangBuzhou ptShichangBuzhou, Model model) {
		model.addAttribute("ptShichangBuzhou", ptShichangBuzhou);
		return "modules/pt/ptShichangBuzhouForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("pt:ptShichang:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated PtShichangBuzhou ptShichangBuzhou) {
		ptShichangBuzhouService.save(ptShichangBuzhou);
		return renderResult(Global.TRUE, text("保存成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("pt:ptShichang:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(PtShichangBuzhou ptShichangBuzhou) {
		ptShichangBuzhouService.delete(ptShichangBuzhou);
		return renderResult(Global.TRUE, text("删除成功！"));
	}
	
}